$(function() {
	admin.userBase.init();
});
Namespace('admin.userBase', {
	init : function() {
		easyui.util.initDatagrid('#datagrid', {
			onDblClickRow : function() {
			}
		});
	},
	query : function() {
		if (!$('#query-form').form('validate'))
			return;
		var data = $('#query-form').form('jsonObject');
		$('#datagrid').datagrid('load', data);
	},
	detail:function(id) {
		if (id != null) {
			top.addTab(id,'用户详情', contextPath+'/user/base/detail?userId=' + id);
		}
	},
	auth:function(id) { //认证
		if (id != null) {
			top.addTab(id,'身份认证详情', contextPath+'/user/auth/detail?userId=' + id);
		}
	},
	authCommunity:function(id) { //社区认证
		if (id != null) {
			top.addTab(id,'社区住户认证', contextPath+'/user/base/authCommunity?userId=' + id);
		}
	},
	passAuthCommunity:function(userId) { //社区住户认证通过
		if(!$('#data-form').form('validate')) return;
		if (userId != null) {
			$.messager.confirm('信息提示', "确定认证通过?", function (success) {
				if (!success) {
					return;
				}
	            var url = contextPath + '/user/base/passAuthCommunity';
				$.post(url, {userId:userId}, function (result) {
					if (result.code == 1) {
						top.showInfo('操作成功');
					} else {
						top.showInfo(result.msg);
					}
				});

			});
		}
	},
	through:function(userId) { //认证通过
		if(!$('#data-form').form('validate')) return;
		if (userId != null) {
			$.messager.confirm('信息提示', "确定认证通过?", function (success) {
				if (!success) {
					return;
				}
				var data = $('#data-form').form('jsonObject');
				data.birthAt = data.birthAt + " 00:00:00";
	            var url = contextPath + '/user/auth/through';
				$.post(url, data, function (result) {
					if (result.code == 1) {
						top.showInfo('操作成功');
					} else {
						top.showInfo(result.msg);
					}
				});

			});
		}
	},
	notthrough:function(userId) { //认证不通过
		if (userId != null) {
			$.messager.confirm('信息提示', "确定不通过?", function (success) {
				if (!success) {
					return;
				}
	            var url = contextPath + '/user/auth/notthrough';
				$.post(url, {'userId': userId}, function (result) {
					if (result.code == 1) {
						top.showInfo('操作成功');
					} else {
						top.showInfo(result.msg);
					}
				});
			});
		}
	},
	export2Excel : function() {//导出excel
		var url = contextPath + '/user/base/export2Excel';
		var nick = $('#nick').val();
		var communityName = $('#communityName').val();
		var hasIdentityAuth = $('#hasIdentityAuth').val();
		var endAtStr = $("input[name=endAtStr]").val();//$('#endAtStr').val();
		var startAtStr = $("input[name=startAtStr]").val();//$('#startAtStr').val();
		var params ={};
		var paramstr ="";
		//if(nick!='' && nick!=null){
		//	paramstr+="&nick="+nick;
		//}
		//if(communityName!='' && communityName!=null){
		//	paramstr+="&communityName="+communityName;
		//}
		//if(hasIdentityAuth!='' && hasIdentityAuth!=null){
		//	paramstr+="&hasIdentityAuth="+hasIdentityAuth;
		//}
		//if(startAtStr!='' && startAtStr!=null){
		//	paramstr+="&startAtStr="+startAtStr;
		//}
		//if(endAtStr!='' && endAtStr!=null){
		//	paramstr+="&endAtStr="+endAtStr;
		//}
		//if(paramstr!=''){
		//	url += "?"+paramstr;
		//}
		url += "?"+ $('#query-form').serialize()
			+ "&rows=" + $('.pagination-page-list option:selected').val()
			+ "&page=" + $('.pagination-num').val();

		window.open(url,"");
		
	},
	setIsOfficial: function (id) {
		var tip = "确定设为官方用户吗";
		$.messager.confirm('信息提示', tip, function (success) {
			if (!success) {
				return;
			}
            var url = contextPath + '/user/base/setIsOfficial';
			$('#datagrid').datagrid('loading');
			$.post(url, {'id': id}, function (result) {
				$('#datagrid').datagrid('loaded');
				if (result.code == 1) {
					top.showInfo('操作成功');
                    admin.userBase.query();
				} else {
					top.showInfo(result.msg);
				}
			});

		});
	},
	setNotOfficial: function (id) {
		var tip = "确定取消官方用户吗";
		$.messager.confirm('信息提示', tip, function (success) {
			if (!success) {
				return;
			}
            var url = contextPath + '/user/base/setNotOfficial';
			$('#datagrid').datagrid('loading');
			$.post(url, {'id': id}, function (result) {
				$('#datagrid').datagrid('loaded');
				if (result.code == 1) {
					top.showInfo('操作成功');
                    admin.userBase.query();
				} else {
					top.showInfo(result.msg);
				}
			});

		});
	},
	setIsOnlineService: function (id) {
		var tip = "确定设为在线客服吗";
		$.messager.confirm('信息提示', tip, function (success) {
			if (!success) {
				return;
			}
            var url = contextPath + '/user/base/setIsOnlineService';
			$('#datagrid').datagrid('loading');
			$.post(url, {'id': id}, function (result) {
				$('#datagrid').datagrid('loaded');
				if (result.code == 1) {
					top.showInfo('操作成功');
                    admin.userBase.query();
				} else {
					top.showInfo(result.msg);
				}
			});

		});
	},
	setNotOnlineService: function (id) {
		var tip = "确定取消在线客服吗";
		$.messager.confirm('信息提示', tip, function (success) {
			if (!success) {
				return;
			}
            var url = contextPath + '/user/base/setNotOnlineService';
			$('#datagrid').datagrid('loading');
			$.post(url, {'id': id}, function (result) {
				$('#datagrid').datagrid('loaded');
				if (result.code == 1) {
					top.showInfo('操作成功');
                    admin.userBase.query();
				} else {
					top.showInfo(result.msg);
				}
			});

		});
	},
	sendMoneyAdd:function(id) {
		top.addTab(id,'添加', contextPath+'/user/base/sendMoneyAdd?userId='+id);
	},
	
	moneyAdd: function () {
	 	if(!$('#data-form').form('validate')) return;
        var data=$('#data-form').form('jsonObject');
        var url = contextPath + '/user/base/moneyAdd';
		$.post(url, data, function (result) {
			$('#datagrid').datagrid('loaded');
			if (result.code == 1) {
				top.showInfo('操作成功');
				top.addTab("",'赠送圈币', contextPath+'/user/base/money');
			} else {
				top.showInfo(result.msg);
			}
		});
	},
});